/**
 * Created by WYH on 17/4/13.
 */

angular.module('tribalc').controller('LoginController', ['$rootScope', '$scope', 'Api', '$state', 'Alert',
    function ($rootScope, $scope, Api, $state, Alert) {
        function login() {
            var username = $scope.username;
            var password = $scope.password;
            // $state.go('company.companyProfile')
            if (!username || !password) {
                return Alert.alertBox('账号或密码不能为空')
            }
            Api.login(username, password, function (response) {
                console.log(response);
                localStorage.assign = response.data.assigned;
                localStorage.token = response.data.token;
                $state.go('company.companyProfile')
            })
        }

        if ($rootScope.listenerRootCompanyInfo) {
            $rootScope.listenerRootCompanyInfo();
        }

        $scope.clicklogin = login
        gotoDefaultPage();
        function gotoDefaultPage() {

            if (!Api.getAssign()) {
                return false;
            }
            $state.go('company.companyProfile');

        }
    }]);